<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="livcos.org/ns/doc"
  xmlns:c="livcos.org/ns/cosmos"
  xmlns:m="livcos.org/ns/map"
  xmlns:f="livcos.org/ns/xslt/function"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="doc c f m">
  
  <xsl:import href="../../web/style/doc/document.xsl" />
  <xsl:import href="../../web/style/base.xsl" />
  <xsl:import href="../../web/style/web.xsl" />
  
	<xsl:param name="ref" select="'../data/WebMap'"/>
	<xsl:param name="entity" select="'item_1'"/>
	<xsl:param name="map" select="$ref"/>
	<xsl:param name="item" select="$entity"/>
	
  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="doc-available($map)">
        <xsl:apply-templates select="document($map)/*" mode="run"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="not_found">
          <xsl:with-param name="msg">Cannot find map '<xsl:value-of
            select="$map"/>'!</xsl:with-param>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template name="not_found">
    <xsl:param name="msg"/>
    <html>
      <head>
        <title>Not Found!</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link href="{$toRootPath}/livcos.org/web/css/styles.css" rel="stylesheet" type="text/css"/>
      </head>
      <body>
        <p><xsl:value-of select="$msg"/></p>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="m:map" mode="run">
    <html id="{$viewObjId}">
      <xsl:apply-templates select="m:head"/>
      <xsl:apply-templates select="m:body"/>
    </html>
  </xsl:template>
  
  <xsl:template match="m:head">
    <head>
      <title><xsl:value-of select="m:title" /></title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <meta name="served" content="{current-dateTime()}"/>
      <xsl:call-template name="page_styles"/>
      <xsl:call-template name="page_scripts"/>
      <xsl:call-template name="page_head_extension"/>
    </head>
  </xsl:template>
  
  <xsl:template match="m:head/m:title">
    <p class="title"><xsl:apply-templates/></p>
  </xsl:template>
  
  <xsl:template match="m:body">
    <body>
      <div id="{f:object-id(.)}" class="contentPanel">
        <div class="content">
          <xsl:apply-templates select="../m:head/m:title"/>
          <xsl:apply-templates select="*"/>
        </div>
      </div>
    </body>
  </xsl:template>
  
  <xsl:template match="m:item">
    <div id="{@id}">
      <h2>
        <xsl:apply-templates select="m:label/node()"/>
      </h2>
      <xsl:apply-templates select="doc:*"/>
    </div>
  </xsl:template>
  
  <xsl:template match="m:item/doc:link">
    <p><xsl:apply-imports/></p>
  </xsl:template>
  
</xsl:stylesheet>
